package com.dc.gameserver.extComponents.springDataRedisCache;

import com.dc.gameserver.extComponents.springDataRedisCache.Operations.queueOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * @author 石头哥哥</br>
 *         Date:12/22/13</br>
 *         Time:9:39 PM</br>
 *         Package:com.dc.gameserver.extComponents.redisCache</br>
 *         Comment：基于redis的队列缓存
 */
@Service
public class RedisServiceQueue implements queueOperations {


    @Resource
    private RedisTemplate<Integer, Serializable> redisTemplate;


    /**
     * 将对象添加到队列
     * @param key
     * @param serializable
     */
    @Override
    public void Push(int key, Serializable serializable) {
        redisTemplate.opsForList().leftPush(key,serializable);
    }

    /**
     * 从队列中取出对象
     * @param key
     * @return
     */
    @Override
    public Serializable Pop(int key) {
        return redisTemplate.opsForList().rightPop(key);
    }

    /**
     *从队列中删除对象
     *
     * @param key
     */
    @Override
    public void remove(int key) {
        redisTemplate.delete(key);
    }
}
